// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 * Creator: yanking
 * Create time: 2022-02-21 15:03
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.ThreadPool.ThreadPoolExecute;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.IntStream;

public class ThreadPoolExecute {
    // 使用Java线程池输出数据
    public static void main(String[] args) throws InterruptedException {
        // 当线程池中的线程超过一的时候，无法保证运行的顺序
        ExecutorService es = Executors.newFixedThreadPool(2);
        //  ExecutorService es = Executors.newFixedThreadPool(5);
//        IntStream.rangeClosed(0, 100).forEach(i -> {
//            es.submit(() -> {
//                System.out.print(i + "\t");
//            });
//        });
        ThreadPoolExecutor tp = (ThreadPoolExecutor) es;
        //TimeUnit.SECONDS.sleep(1);
        // 正在运行的线程数量
        //System.out.println(tp.getActiveCount());
        System.out.println(tp.getCorePoolSize());
        tp.setCorePoolSize(Runtime.getRuntime().availableProcessors());
        System.out.println(tp.getCorePoolSize());

    }

    @Test
    public void shout00() {
        IntStream.rangeClosed(0, 100).parallel().forEach(a -> System.out.print(a + "\t"));
    }


}
